
export class ImageReadTool {
  static transImageToUint8Array(image: File): Promise<Uint8Array> {
    const result = new Promise<Uint8Array>((resolve, reject) => {
      const reader = new FileReader();
      reader.readAsArrayBuffer(image);
      reader.onload = () => {
        const uint8Array = new Uint8Array(reader.result as ArrayBuffer);
        resolve(uint8Array);
      };
      reader.onabort = () => {
        reject('load image error');
      };
    });

    return result;
  }

  static transBlobToUrl(source: Blob): Promise<string> {
    const result = new Promise<string>((resolve, reject) => {
      const reader = new FileReader();
      reader.readAsDataURL(source);
      reader.onload = () => {
        resolve(reader.result as string);
      };
      reader.onabort = () => {
        reject('transfer image to url error');
      };
    });
    return result;
  }
}
